#include <bits/stdc++.h>

using namespace std;

const int N=2e3+10;

int n,m;
vector<pair<int,int>> mp[N];
int dist[N],cnt[N];
bool st[N];

bool spfa()
{
	memset(dist,0x3f,sizeof dist);
	dist[1]=0;
	queue<int> q;
	q.push(1);
	st[1]=true;
	
	while(q.size())
	{
		auto u=q.front(); q.pop();
		st[u]=false;
		for(auto& e:mp[u])
		{
			int v=e.first,w=e.second;
			if(dist[u]+w<dist[v])
			{
				dist[v]=dist[u]+w;
				cnt[v]=cnt[u]+1;
				if(cnt[v]>=n) return true;
				if(!st[v]) 
				{
					q.push(v);
					st[v]=true;
				}
			}
		}
	}
	return false;
}

int main() 
{
	int T;cin>>T;
	while(T--)
	{
		memset(mp,0,sizeof mp);
		memset(cnt,0,sizeof cnt);
		memset(st,0,sizeof st);
		
		cin>>n>>m;
		for(int i=1;i<=m;i++)
		{
			int u,v,w;cin>>u>>v>>w;
			mp[u].push_back({v,w}) ;
			if(w>=0) mp[v].push_back({u,w});
		}
		if(spfa()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}	
	return 0;
}
